<?
	include("classes/clsDB.php");
	$r= new ReturnRecord();  // base object for returning data or raw queries
	
	if($_POST['Submit']){
		if($_POST['password']==$_POST['password2']){
			$m= new AddToDatabase();
			$m->AddPosts($_POST,$_FILES);
			$m->AddTable("affiliate");
			$m->AddNoDupe(array("email"));
			$m->DoStuff();
			echo $m->SQL;
			if($m->Errors==""){
				$NewID=$m->ReturnID();
				session_start();
				$_SESSION["AffKey"]=$NewID;
				$_SESSION["Name"]=$_POST['contactName'];
				header("Location: affiliates/home.php");
			}else{
				$Message=$m->Errors;
			}
		}else{
			$Message="Passwords Don't Match";
		}
	};
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Affiliate Sign Up</title>

<link href="css/general.css" rel="stylesheet" type="text/css">
<link href="css/counter.css" rel="stylesheet" type="text/css">
<script src="jscript/general.js" type="text/JavaScript"></script>
<script type="text/JavaScript">
<!--
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following fields are required:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<script>
	function SetPaymentType(){
		var PType=document.getElementById("paymentMethod").value;
		if(PType=="Deposit"){
			var CBank="";
			var CCheque="none";
		}else{
			var CBank="none";
			var CCheque="";
		}
		for(x=1;x<5;x++){
			document.getElementById("bankRow"+x).style.display=CBank;
		}
		for(x=1;x<7;x++){
			document.getElementById("chqRow"+x).style.display=CCheque;
		}
	}
</script>
<body >


  <?php include("header.php"); ?>

<div id="contentHolder">
  <table width="970" border="0" cellspacing="15" cellpadding="0">
    <tr>
      <td valign="top"><p class="pageTitle">Sign Up to the Affiliate Program </p>
        <form name="form1" method="post" action="affiliate-signup.php">
          <?=$Message;?><p><strong>Account Details</strong></p>
          <table width="400" border="0" align="center" cellpadding="0" cellspacing="10">
            <tr>
              <td width="130" height="30">Company Name:</td>
              <td width="354"><input name="companyName" type="text" class="formTextFields" id="companyName" value="<?=$_POST['companyName'];?>" size="40">
              *</td>
            </tr>
            <tr>
              <td height="30">Contact Name:</td>
              <td><input name="contactName" type="text" class="formTextFields" id="contactName" value="<?=$_POST['contactName'];?>" size="40">
              *</td>
            </tr>
            <tr>
              <td height="30">Email Address: </td>
              <td><input name="email" type="text" class="formTextFields" id="email" value="<?=$_POST['email'];?>" size="40">
              *</td>
            </tr>
            <tr>
              <td height="30">Phone:</td>
              <td><input name="phone" type="text" class="formTextFields" id="phone" value="<?=$_POST['phone'];?>" size="40">
              *</td>
            </tr>
            <tr>
              <td height="30">Username:</td>
              <td><input name="username" type="text" class="formTextFields" id="username" value="<?=$_POST['username'];?>" size="40">
              *</td>
            </tr>
            <tr>
              <td>Password:</td>
              <td><input name="password" type="password" class="formTextFields" id="password4" size="40">
              *</td>
            </tr>
            <tr>
              <td height="36">Confirm Password:</td>
              <td><input name="password2" type="password" class="formTextFields" id="password5" size="40">
              *</td>
            </tr>
            <tr>
              <td height="36" colspan="2"><input type="checkbox" name="checkbox" value="checkbox">
                I agree to the Bubble Affiliate Program <a href="#">Terms and Conditions</a>.</td>
            </tr>
            <tr>
              <td height="36" colspan="2"><input name="emailSubscribe" type="checkbox" value="checkbox" checked>
                I would like to receive 'The Juice' email updates including the weekly accommodation specials.</td>
            </tr>
          </table>
          <p><strong>Payment Details</strong></p>
          <table width="400" border="0" align="center" cellpadding="0" cellspacing="10">
            <tr>
              <td width="130" height="30">Select Payment Method:</td>
              <td width="354"><select name="paymentMethod" class="formTextFields"  id="paymentMethod" onChange="SetPaymentType()">
                  <option value="Deposit" <?=($_POST['paymentMethod']=="Deposit" ? "selected" :"");?>>Direct Deposit</option>
                  <option value="Cheque" <?=($_POST['paymentMethod']=="Cheque" ? "selected" :"");?>>Pay By Cheque</option>
                </select>              </td>
            </tr>
            <tr id="bankRow1">
              <td height="30">Bank Name: </td>
              <td><input name="bankName" type="text" class="formTextFields" id="bankName" value="<?=$_POST['bankName'];?>" size="40"></td>
            </tr>
            <tr id="bankRow2">
              <td height="30">Name On Account: </td>
              <td><input name="bankAccount" type="text" class="formTextFields" id="bankAccount" value="<?=$_POST['bankAccount'];?>" size="40"></td>
            </tr>
            <tr id="bankRow3">
              <td height="30">BSB:</td>
              <td><input name="bankBsb" type="text" class="formTextFields" id="bankBsb" value="<?=$_POST['bankBsb'];?>" size="40"></td>
            </tr>
            <tr id="bankRow4">
              <td height="30">Account Number: </td>
              <td><input name="bankNumber" type="text" class="formTextFields" id="bankNumber" value="<?=$_POST['bankNumber'];?>" size="40"></td>
            </tr>
            <tr id="chqRow1">
              <td height="30">Address</td>
              <td><input name="chqAddress" type="text" class="formTextFields" id="chqAddress" value="<?=$_POST['chqAddress'];?>" size="40"></td>
            </tr>
            <tr id="chqRow2">
              <td height="30">Suburb</td>
              <td><input name="chqSuburb" type="text" class="formTextFields" id="chqSuburb" value="<?=$_POST['chqSuburb'];?>" size="40"></td>
            </tr>
            <tr id="chqRow3">
              <td height="30">State</td>
              <td><input name="chqState" type="text" class="formTextFields" id="chqState" value="<?=$_POST['chqState'];?>" size="40"></td>
            </tr>
            <tr id="chqRow4">
              <td height="30">Country</td>
              <td><input name="chqCountry" type="text" class="formTextFields" id="chqCountry" value="<?=$_POST['chqCountry'];?>" size="40"></td>
            </tr>
            <tr id="chqRow5">
              <td height="30">PostCode</td>
              <td><input name="chqPostcode" type="text" class="formTextFields" id="chqPostcode" value="<?=$_POST['chqPostcode'];?>" size="40"></td>
            </tr>
            <tr id="chqRow6">
              <td height="30">Name On Cheque</td>
              <td><input name="chqName" type="text" class="formTextFields" id="chqName" value="<?=$_POST['chqName'];?>" size="40"></td>
            </tr>
            <tr>
              <td height="30">GST:</td>
              <td><input name="gst" type="checkbox" id="gst" value="1" <?=($_POST['gst']==1 ? "checked" :"");?>>
                I am eligible to collect GST </td>
            </tr>
            <tr>
              <td>ABN:</td>
              <td><input name="abn" type="text" class="formTextFields" id="abn" value="<?=$_POST['abn'];?>" size="40"></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><input name="Submit" type="submit" class="formButton" onClick="MM_validateForm('companyName','','R','contactName','','R','email','','RisEmail','phone','','RisNum','username','','R','password4','','R','password5','','R');return document.MM_returnValue"  value="Sign Up"></td>
            </tr>
          </table>
        </form>
        <p>&nbsp;</p>
      <p>&nbsp;</p>      </td>
      <td width="260" valign="top"><table width="260" border="0" cellspacing="0" cellpadding="10" id="sideBar">
        <tr>
          <td height="25" class="sideBarHeader"><strong>How It All Works </strong></td>
        </tr>
        <tr>
          <td class="sideBarContent"><p>Information on the affiliate program here </p>
            </td>
        </tr>
        <tr>
          <td height="25" align="right" class="sideBarFooter">&nbsp;</td>
        </tr>
      </table></td>
    </tr>
  </table>
</div>

<div id="footer"><?php include("footer.php"); ?></div>

</body>
</html>
